﻿using System;
using System.Linq;
using DynCMS.NET.Core.Entities;
using DynCMS.NET.DataAccess.Implementation;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace DynCMS.NET.DataAccess.Test
{
    [TestClass]
    public class DataContextTests : BaseDataContextTest
    {
        [TestMethod]
        public void ConstructorTest()
        {
            DataContext dc = new DataContext();
            Assert.IsNotNull(dc.InstanceId);
            Assert.AreNotEqual(Guid.Empty, dc.InstanceId);
        }

        [TestMethod]
        public void ConnectTest()
        {
            DataContext dc = new DataContext();

            Assert.IsTrue(dc.Database.Exists());
        }

        [TestMethod]
        public void PageCRTest()
        {
            DataContext dc = new DataContext();

            var page = new DynCMS.NET.Core.Entities.Page()
            {
                Url = "~",
                ParentUrl = "~",
                Children = new System.Collections.Generic.List<Page>()
            };
            page.Parent = page;
            page.Children.Add(page);
            dc.Pages.Add(page);
            int rowCount = dc.SaveChanges();
            Assert.AreEqual<int>(1, rowCount);

            page = dc.Pages.Single(p => p.ParentUrl == "~");
            Assert.IsNotNull(page);
        }
    }
}